//-----------------Sonic CD Help Menu Script------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0	:	Object.Timer		//Also used for fading
#alias Object.Value2	:	Object.YOffset
#alias Object.Value3	:	Object.HelpPage
#alias Object.Value4	:	Object.PageTimer

// States
#alias 0	:	HELPMENU_SETUP
#alias 1	:	HELPMENU_FADEIN
#alias 2	:	HELPMENU_CONTROLS
#alias 3	:	HELPMENU_PAGEDOWN
#alias 4	:	HELPMENU_PAGEUP
#alias 5	:	HELPMENU_LEAVE

// Languages
#alias 0	:	LANG_ENGLISH
#alias 1	:	LANG_FRENCH
#alias 2	:	LANG_ITALIAN
#alias 3	:	LANG_DEUTSCH
#alias 4	:	LANG_SPANISH
#alias 5	:	LANG_JAPANESE

// Global SFX
#alias 26	:	SFX_G_OUTTAHERE
#alias 27	:	SFX_G_SELECT

// Soundtrack
#alias 0	:	OST_JP

// Presentation Stages
#alias 1	:	STAGE_P_MENU

// Engine & Callbacks
#alias 5	:	ENGINE_ENTER_HIRESMODE
#alias 6	:	ENGINE_EXIT_HIRESMODE

// Priority
#alias 1	:	PRIORITY_ACTIVE

// Function declarations
#function HelpMenu_PageLoad

function HelpMenu_PageLoad
	switch Object.HelpPage
	case 0
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg1_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg1_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg1_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg1_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg1_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg1_JP.txt", 1)
			break
		end switch
		break
	case 1
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg2_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg2_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg2_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg2_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg2_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg2_JP.txt", 1)
			break
		end switch
		break
	case 2
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg3_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg3_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg3_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg3_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg3_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg3_JP.txt", 1)
			break
		end switch
		break
	case 3
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg4_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg4_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg4_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg4_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg4_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg4_JP.txt", 1)
			break
		end switch
		break
	case 4
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg5_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg5_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg5_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg5_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg5_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg5_JP.txt", 1)
			break
		end switch
		break
	case 5
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg6_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg6_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg6_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg6_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg6_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg6_JP.txt", 1)
			break
		end switch
		break
	case 6
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg7_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg7_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg7_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg7_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg7_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg7_JP.txt", 1)
			break
		end switch
		break
	case 7
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg8_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg8_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg8_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg8_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg8_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg8_JP.txt", 1)
			break
		end switch
		break
	case 8
		switch Engine.Language
		case LANG_ENGLISH
			LoadTextFile(MENU_1, "Data/Game/EN_Help/SCD_Pg9_EN.txt", 1)
			break
		case LANG_FRENCH
			LoadTextFile(MENU_1, "Data/Game/FR_Help/SCD_Pg9_FR.txt", 1)
			break
		case LANG_ITALIAN
			LoadTextFile(MENU_1, "Data/Game/IT_Help/SCD_Pg9_IT.txt", 1)
			break
		case LANG_DEUTSCH
			LoadTextFile(MENU_1, "Data/Game/DE_Help/SCD_Pg9_DE.txt", 1)
			break
		case LANG_SPANISH
			LoadTextFile(MENU_1, "Data/Game/ES_Help/SCD_Pg9_ES.txt", 1)
			break
		case LANG_JAPANESE
			LoadTextFile(MENU_1, "Data/Game/JP_Help/SCD_Pg9_JP.txt", 1)
			break
		end switch
		break
	end switch
end function


sub ObjectMain
	switch Object.State
	case HELPMENU_SETUP
		TempValue0  = 256
		TempValue0 -= Screen.CenterX
		Screen.XOffset  = TempValue0
		Object.HelpPage = 0
		CallFunction(HelpMenu_PageLoad)
		PlayMusic(1)
		Object.Timer = 384
		Object.State++
		SetScreenFade(0, 0, 0, 255)
		break

	case HELPMENU_FADEIN
		if Object.Timer > 0
			Object.Timer -= 8
		else
			Object.State++
		end if
		SetScreenFade(0, 0, 0, Object.Timer)
		break

	case HELPMENU_CONTROLS
		if KeyPress[0].Down == true
			if Object.HelpPage < 8
				PlaySfx(SFX_G_SELECT, false)
				Object.Timer = 256
				Object.State = HELPMENU_PAGEDOWN
			end if
		end if

		if KeyPress[0].Up == true
			if Object.HelpPage > 0
				PlaySfx(SFX_G_SELECT, false)
				Object.State = HELPMENU_PAGEUP
			end if
		end if
		
		if KeyPress[0].ButtonB == true
			PlaySfx(SFX_G_OUTTAHERE, false) 
			Object.State = HELPMENU_LEAVE
		end if
		break

	case HELPMENU_PAGEDOWN
		if Object.Timer > 0
			Cos(TempValue0, Object.Timer)
			TempValue0 	 >>= 1
			TempValue0 	  += 256
			TempValue1	   = Object.YOffset
			TempValue1	  += TempValue0
			Screen.YOffset = TempValue1

			TempValue1  += 256
			TempValue1 >>= 9
			if TempValue1 > Object.HelpPage
				Object.HelpPage++
				if Object.HelpPage == 2
					SetActivePalette(1, 0, Screen.YSize)
				else
					SetActivePalette(0, 0, Screen.YSize)
				end if
				CallFunction(HelpMenu_PageLoad)
			end if

			Object.Timer -= 3
			if Object.Timer < 0
				Object.Timer = 0
			end if
		else
			Object.YOffset += 512
			Screen.YOffset = Object.YOffset
			Object.State = HELPMENU_CONTROLS
		end if
		break

	case HELPMENU_PAGEUP
		if Object.Timer < 256
			Cos(TempValue0, Object.Timer)
			TempValue0   >>= 1
			TempValue0 	  -= 256
			TempValue1 	   = Object.YOffset
			TempValue1	  += TempValue0
			Screen.YOffset = TempValue1

			TempValue1  += 256
			TempValue1 >>= 9
			if TempValue1 < Object.HelpPage
				Object.HelpPage--
				if Object.HelpPage == 2
					SetActivePalette(1, 0, Screen.YSize)
				else
					SetActivePalette(0, 0, Screen.YSize)
				end if
				CallFunction(HelpMenu_PageLoad)
			end if
			
			Object.Timer += 3
			if Object.Timer > 256
				Object.Timer = 256
			end if
		else
			Object.YOffset -= 512
			Screen.YOffset  = Object.YOffset

			Object.Timer = 0
			Object.State = HELPMENU_CONTROLS
		end if
		break

	case HELPMENU_LEAVE
		if Object.Timer < 348
			Object.Timer += 8
		else
			Stage.ListPos = STAGE_P_MENU
			Engine.State = ENGINE_EXIT_HIRESMODE
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, Object.Timer)
		break

	end switch
end sub


sub ObjectDraw
	Object.PageTimer--
	if Object.PageTimer < -31
		Object.PageTimer += 32
	end if
	TempValue1   = Object.PageTimer
	TempValue1 >>= 1
	while TempValue1 < Screen.YSize
		TempValue0   = Object.PageTimer
		TempValue0 >>= 1
		while TempValue0 < Screen.XSize
			DrawSpriteScreenXY(0, TempValue0, TempValue1)
			TempValue0 += 128
		loop
		TempValue1 += 128
	loop
end sub


sub ObjectStartup
	LoadSpriteSheet("Menu/HelpBG.gif")

	SpriteFrame(0, 0, 128, 128, 1, 1)

	if Engine.Language == LANG_JAPANESE
		Object[59].XPos -= 0x100000
		Object[60].XPos -= 0x100000
		Object[61].XPos -= 0x100000
		Object[62].XPos -= 0x100000
		Object[63].XPos -= 0x100000
		Object[64].XPos += 0x500000
		Object[59].YPos += 0x180000
		Object[60].YPos += 0x180000
		Object[61].YPos += 0x180000
		Object[62].YPos += 0x180000
		Object[63].YPos += 0x180000
		Object[64].YPos -= 0x2F0000
	end if

	LoadPalette("HelpPal1.act", 0, 0, 0, 256)
	LoadPalette("HelpPal2.act", 1, 0, 0, 256)
	LoadTextFont("Data/Game/HelpText.bin")

		SetMusicTrack("JP/Menu.ogg", 1, 1)

	Engine.State		 = ENGINE_ENTER_HIRESMODE
	Screen.CameraEnabled = false

	Object[0].Type		= TypeName[Help Menu]
	Object[0].Priority  = PRIORITY_ACTIVE	
	Object[0].DrawOrder = 0
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("Menu/MenuGfx2_EN.gif")
	SpriteFrame(16, 0, 46, 30, 1, 677)	// Help

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
